import * as types from './action-types'

const defaultState = {
  inputValue: '',
  list: []
}

/* eslint-disable default-case */
export default (state = defaultState, action) => {
  const { type } = action

  if (type.indexOf('@@') === -1) {
    const newState = JSON.parse(JSON.stringify(state))

    switch (type) {
      case types['INPUT_CHANGE']:
        newState.inputValue = action.value
        break
      case types['BUTTON_CLICK']:
        newState.list.push(action.value)
        newState.inputValue = ''
        break
      case types['DELETE_CLICK']:
        newState.list.splice(action.value, 1)
        break
      case types['INIT_LIST']:
        newState.list = action.value
        break
    }

    return newState
  } else {
    return state
  }
}
/* eslint-enable */
